<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>新品有戏后台管理</title>
    <link href="__CSS__/boot.css" rel="stylesheet">
    <link href="__STATIC__/layui/css/layui.css" rel="stylesheet">
    <script src="__JS__/jquery.js"></script>
    <script src="__JS__/layer/layer.js"></script>
    <script src="__STATIC__/layui/layui.js"></script>
    <style>
        tr td{
            text-align: center;
            vertical-align: middle!important;
        }
    </style>
</head>
<body>
{include file="base/header"}
<table class="layui-table">
    <tbody>
    <tr>
        <td>商品名称</td>
        <td>邮寄地址</td>
        <td>联系人</td>
        <td>联系电话</td>
        <td>购买个数(个)</td>
        <td>单价(元)</td>
        <td>快递公司</td>
        <td>状态</td>
        <td>操作</td>
    </tr>
    {foreach $result as $val}
    <tr>
        <td>{$val.pname}</td>
        <td>{$val.province}{$val.city}{$val.county}{$val.town}{$val.address}</td>
        <td>{$val.linkman}</td>
        <td>{$val.telephone}</td>
        <td>{$val.number}</td>
        <td>{$val.price}</td>
        <td>{$val.express}</td>
        {if $val.status == 1}
            <td style="color: red">新订单</td>
        {elseif $val.status == 2}
            <td style="color: blue;">以发货</td>
        {elseif $val.status == 3}
            <td>已到</td>
        {/if}
        <td>
            {if $val.status == 1}
                <button type="button" onclick="edit({$val.id})" class="btn btn-primary btn-xs">编辑</button>
                <button type="button" onclick="mail({$val.id})" class="btn btn-info btn-xs">发货</button>
            {elseif $val.status == 2/}
                <button type="button" disabled class="btn btn-primary btn-xs">编辑</button>
                <button type="button" onclick="reach({$val.id})" class="btn btn-info btn-xs">已到</button>
            {else}
                <button type="button" disabled class="btn btn-primary btn-xs">编辑</button>
                <button type="button" disabled class="btn btn-info btn-xs">已到</button>
            {/if}
        </td>
    </tr>
    {/foreach}
    </tbody>
</table>
{$result->render()}
</body>
<script>
    //编辑
    function edit(id) {
        layer.open({
            title:"编辑",
            type:2,
            area: ['800px', '600px'],
            anim:2,
            content:"{:url('online/mail/edit')}?id="+id
        });
    }
    //已到
    function reach(id) {
        $.ajax({
            url:"{:url('online/mail/reach')}",
            data:"id="+id,
            type:"post",
            dataType:"json",
            success:function (res) {
                if(res.success){
                    layer.alert(res.success,{bnt:['确定','取消']},function () {
                        window.location.reload();
                    },function () {
                        window.location.reload();
                    });
                }
            }
        });
    }
    //邮寄
    function mail(id) {
        layer.prompt({title: '请填写快递公司', formType: 2},
            function (express) {
                if(!express){
                    layer.alert('请填写快递公司');
                    return;
                }
                $.ajax({
                    url:"{:url('online/mail/delivery')}",
                    data:"id="+id+"&express="+express,
                    type:"post",
                    dataType:"json",
                    success:function (res) {
                        if(res.success){
                            layer.alert(res.success,{bnt:['确定']},function () {
                                window.location.reload();
                            });
                        }else if(res.error){
                            layer.alert(res.error);
                        }
                    }
                });
            }
        );
    }
</script>
</html>